<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>设备类别管理</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<jsp:include page="../resource.jsp"></jsp:include> 
	<script type="text/javascript">
	var ptId = '';  //单击选中的节点的ID
	$(document).ready(function() {
		
		var h = '85%';
 		if($.browser.msie && ($.browser.version == 8.0 || $.browser.version == 9.0)){
 	    	 h = $(self.parent.parent.frames['mainFrame']).height()-87; 
 	    }
        $('#hdType').omGrid({
        	dataSource : 'hdType!queryList.do',
            height : h,
            limit : 20,
            showIndex : true,
            colModel : [ 
                         {header : '类别名称', name : 'name', width : 120, align : 'center'}
                         ,{header : '是否启用', name : 'enable', width : 90, align : 'center',renderer:function(value){
                             return value?'启用':'禁用';
                         }}
                         ]
        });
        
        $
        
        $('#postformbtn').omButton({});
        
        $('#typeEditor').omDialog({
        	autoOpen: false,
  		    height: 150,
  		    width : 400,
	  		buttons: [{
	              text : "确定", 
	              click : function () {
	                $('#typeForm').submit();
	              }
	           }, {
	              text : "取消", 
	              click : function () {
	                $("#typeEditor" ).omDialog("close");
	            }
	        }]
        });
        
        $('#typeAdd').click(function(){
        	$('#typeEditor').omDialog("open");
        	$('#hdTypeId').val('');
        	$('#typeForm').resetForm();
        });
        
        $('#typeModify').click(function(){
        	var selects = $("#hdType").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择修改的记录'});
        		return;
        	}
        	$('#typeEditor').omDialog("open");
        	$('#typeForm').resetForm();
        	$('#hdTypeId').val(selects[0].id);
        	$('#hdTypeName').val(selects[0].name);
        	$('#hdTypeState').val(selects[0].enable?'true':'false');
        });
        
        $("#typeDelete").click(function(){
        	var selects = $("#hdType").omGrid("getSelections",true);
        	if(selects.length <= 0){
        		$.omMessageBox.alert({content:'请您选择删除的记录'});
        		return;
        	}
        	 $.omMessageBox.confirm({
                 title:'确认删除',
                 content:'您确定删除该类别？',
                 onClose:function(result){
                	 if(result){
                		 $.ajax({
                			 url : 'hdType!delete.do',
                			 data : {id:selects[0].id},
                			 success : function(data){
                				 if(data == '1'){
                					 $.omMessageTip.show({timeout : 2000,content : '删除成功！'});
                					 $('#hdType').omGrid("reload");
                				 }else{
                					 $.omMessageTip.show({timeout : 2000,content : '删除失败！'});
                				 }
                			 }
                		 });
                	 }
                 }
             });
        });
        
        var typeOptions  = {
        		  url : 'hdType!save.do',
                  success : function(data){
                     	if(data == '1'){  
                         	$.omMessageTip.show({timeout : 2000,content : '保存成功！'});
                         	$('#typeEditor').omDialog('close');
                         	$('#hdType').omGrid("reload");
                     	}else{
                     		$.omMessageTip.show({timeout : 2000,content : '保存失败！',type : 'error'});
                     	}
                  }
        	  };
      	  $('#typeForm').submit(function() {
                $(this).omAjaxSubmit(typeOptions);
                return false;//返回false,阻止浏览器默认行为
          });
      	
    });
	</script>  
  </head>
  
  <body>
    <div class="toolbar mar">
		         <a href="#" class="rbutton" id="typeAdd"><span><img src="../images/add.gif" width="14" height="14" /><ins>添加</ins></span></a>
		         <a  class="line"></A>
		         <a href="#" class="rbutton" id="typeModify"><span><img src="../images/add.gif" width="14" height="14" /><ins>修改</ins></span></a>
		         <a  class="line"></A>
		         <a href="#" class="rbutton" id="typeDelete"><span><img src="../images/del.gif" width="14" height="14" /><ins>删除</ins></span></a>
		         <a  class="line"></A>
	</div>
    <table id="hdType"></table>
    
    <div id="typeEditor" title="类别修改" style="display: none;">
     <form id="typeForm" method="post">
          <table width="100%" border="0" class="grid_layout" cellspacing="0" height="100%">
             <tr>
               <td width="20%" align="right">类别名称：</td>
               <td width="68%" colspan="3">
                 <input type="hidden" name="hdType.id" id="hdTypeId">
                 <input type="text" name="hdType.name" id="hdTypeName" class="input_text"/>
               </td>
             </tr>
             <tr>
             	<td width="20%" align="right" >是否启用：</td>
             	<td width="68%" colspan="3">
             		<select name="hdType.enable" id="hdTypeState">
             			<option value="true">启用</option>
             			<option value="false">禁用</option>
             		</select>
             	</td>
             </tr>
           </table>
         </form>
   </div>
  </body>
</html>
